#!/bin/csh
#
# csh script to produce averages results
#
foreach infile ( alucomb_average_constrained.input \
                 alucomb_average_constrained_aleph_hcorr.input \
                 alucomb_average_rescaled_constrained.input \
                 alucomb_average_rescaled_constrained_aleph_hcorr.input \
                 alucomb_average_unconstrained.input \
                 alucomb_average_unconstrained_aleph_hcorr.input \
                 alucomb_average_rescaled_unconstrained.input \
                 alucomb_average_rescaled_unconstrained_aleph_hcorr.input )
 setenv rdatafile `echo $infile  | awk -F. '{print $1".rdata"}'`
 setenv logfile `echo $infile  | awk -F. '{print $1".log"}'`
 setenv listfile `echo $infile  | awk -F. '{print $1".list"}'`
 setenv resfile `echo $infile  | awk -F. '{print $1".res"}'`
 setenv resfile2 `echo $infile  | awk -F. '{print $1".res2"}'`
 setenv showfile `echo $infile  | awk -F. '{print $1".show"}'`
 rm -f average.input
 ln -s $infile average.input
 make alucomb
 cp -p average_alucomb.rdata $rdatafile
 cp -p average_alucomb.log $logfile
 rm -f $listfile ; ../../../Common/bin/aluelab-list.r | tee $listfile
# rm -f $showfile ; ./aluelab-show.r | tee $showfile
# rm -f $resfile ; ./aluelab-results.r -lepuniv | tee $resfile
# echo $infile | grep -q _unconstrained
# if ( $? == 0 ) then
#   rm -f $resfile2 ; ./aluelab-results.r -vadirect | tee $resfile2
#   if ( $1 == 1 ) then
#     cp -p $resfile2 log 
#   endif
# endif
 if ( $1 == 1 ) then 
   cp -p $logfile  log 
   cp -p $listfile log 
   cp -p $showfile log 
   cp -p $resfile  log 
 endif
end
